﻿var Module_SoftList;
var Module_SoftStore;
// 功能模块grid展示
Module_SoftList = function() {
    var url = "/manager/Module_Soft/List";
    var sm = Ext.create('Ext.selection.CheckboxModel');

    //grid 填充
    Ext.define('Module_SoftGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            { name: "Id", type:"string"},
            { name: "ChannelId", type:"string"},
            { name: "ClassId", type:"string"},
            { name: "Title", type:"string"},
            { name: "TColor", type:"string"},
            { name: "AddDate", type:"datetime"},
            { name: "Summary", type:"string"},
            { name: "Editor", type:"string"},
            { name: "Author", type:"string"},
            { name: "Tags", type:"string"},
            { name: "ViewNum", type:"string"},
            { name: "IsPass", type:"string"},
            { name: "IsImg", type:"string"},
            { name: "Img", type:"string"},
            { name: "OrderNum", type:"string"},
            { name: "UserId", type:"string"},
            { name: "ReadGroup", type:"string"},
            { name: "SourceFrom", type:"string"},
            { name: "Version", type:"string"},
            { name: "OperatingSystem", type:"string"},
            { name: "UnZipPass", type:"string"},
            { name: "DemoUrl", type:"string"},
            { name: "RegUrl", type:"string"},
            { name: "SSize", type:"string"},
            { name: "Points", type:"string"},
            { name: "DownUrl", type:"string"},
            { name: "DownNum", type:"string"},
            { name: "OutUrl", type:"string"},
            { name: "ReadComment", type:"string"},
            { name: "WriteComment", type:"string"},
            { name: "AgainstNum", type:"string"},
            { name: "SupportNum", type:"string"},
            { name: "Enabled", type:"string"}
            ]
    });

    //grid获取 json数组
    Module_SoftStore = Ext.create('Ext.data.Store', {
        pageSize: CMN.pageSize,
        model: 'Module_SoftGridModel',
        buffered: false,  //是否动态加载
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: url,
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },
        sorters: [{
            property: 'Id',
            direction: 'DESC'
}]
        });

        //分页设置
        var pagingBar = Ext.create('Ext.PagingToolbar', {
            displayInfo: true, emptyMsg: "没有数据显示", displayMsg: "显示从{0}条数据到{1}条数据，共{2}条数据",
            store: Module_SoftStore,
            pageSize: CMN.pageSize,
            //显示右下角信息
            prevText: "上一页",
            nextText: "下一页",
            refreshText: "刷新",
            lastText: "最后页",
            firstText: "第一页",
            beforePageText: "当前页",
            afterPageText: "共{0}页"
        });

        //删除选中行信息
        DeleteModule_SoftFn = function() {
            var row = Ext.getCmp("Module_SoftPanel").getSelectionModel().getSelection();
            if (row.length == 0) {
                Ext.Msg.alert("提示信息", "请您至少选择一个!");
            }
            else if (row.length > 1) {
                var idList = "";
                for (var i = 0; i < row.length; i++) {
                    if (i == 0) {
                        idList = row[0].data.Id;
                    }
                    else {
                        idList = idList +"_" + row[i].data.Id;
                    }
                }
                //Ext.Msg.alert("提示信息", "对不起只能选择一个!");
                Ext.Msg.confirm("提 示!", "您确定要删除" + idList + "吗?", function(btn) {
                    if (btn == "yes") {
                        Ext.Ajax.request({
                            url: "/manager/Module_Soft/DeleteList/" + idList,
                            method: "get",
                            success: function(d) {
                                //成功后
                                var action = Ext.JSON.decode(d.responseText);
                                //alert(action.success);
                                var flag = action.success;
                                if (flag == "true") {
                                    Module_SoftStore.loadPage(1);
                                    Ext.MessageBox.alert("恭喜", "删除成功!");
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("删除失败!", message);
                                    }
                                    else {
                                        Ext.MessageBox.alert("提示!", "删除失败!");
                                    }
                                }
                            },
                            failure: function(form, action) {
                                Ext.MessageBox.alert("提示!", "修改失败!");
                            }
                        })
                    }
                    else {

                    }
                })
            }
            else if (row.length == 1) {
                Ext.Msg.confirm("提 示!", "您确定要删除" + row[0].data.Id + "吗?", function(btn) {
                    if (btn == "yes") {
                        Ext.Ajax.request({
                            url: "/manager/Module_Soft/Delete/" + row[0].data.Id,
                            method: "POST",
                            success: function(d) {
                                //成功后
                                var action = Ext.JSON.decode(d.responseText);
                                //alert(action.success);
                                var flag = action.success;
                                if (flag == "true") {
                                    Module_SoftStore.loadPage(1);
                                    Ext.MessageBox.alert("恭喜", "删除成功!");
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("删除失败!", message);
                                    }
                                    else {
                                        Ext.MessageBox.alert("提示!", "删除失败!");
                                    }
                                }
                            },
                            failure: function(form, action) {
                                Ext.MessageBox.alert("提示!", "修改失败!");
                            }
                        })
                    }
                    else {

                    }
                })
            }
        }


        //修改选中行信息
        EditModule_SoftFn = function() {
            var row = Ext.getCmp("Module_SoftPanel").getSelectionModel().getSelection();
            if (row.length == 0) {
                Ext.Msg.alert("提示信息", "您没有选中任何行!");
            }
            else if (row.length > 1) {
                Ext.Msg.alert("提示信息", "对不起只能选择一个!");
            } else if (row.length == 1) {
                EditModule_Soft(row[0].data.Id);
            }

        }

        //新增信息
        SaveModule_SoftFn = function() {
            InsertModule_Soft();
        }

        //grid配置
        var grid = Ext.create('Ext.grid.Panel', {
            id: "Module_SoftPanel",
            renderTo: "Module_SoftGrid",
            layout: "fit",
            alias: 'widget.methodPanel',
            columnLines: true,
            loadMask: true,
            frame: true,
            border: false,
            selModel: sm,   //选择框
            autoScroll: true,
            store: Module_SoftStore,
            ds: Module_SoftStore,
            sm: sm,
            columnLines: true,
            //cm: cm2,
            viewConfig: {
                stripeRows: true,
                trackOver: true,
                emptyText: '<div style="color:#999;margin:5px;">当前没有记录显示<div>'
            },
            stripeRows: true,
            listeners: {
                "itemdblclick": function(g, rowIndex, e) {
                    EditModule_SoftFn();
                }
            },
            bbar: pagingBar,
            tbar: [            		 //工具条设置
            		 {
            		 text: "新增",
            		 tooltip: "新增",
            		 iconCls: "addicon",
            		 handler: SaveModule_SoftFn
           }, "", "-", "", {
               text: "编辑",
               tooltip: "编辑",
               iconCls: "editicon",
               handler: EditModule_SoftFn
           }, "", "-", "", {
               text: "删除",
               tooltip: "删除",
               iconCls: "deleteicon",
               handler: DeleteModule_SoftFn
           }, "-"],
            columns: [
               Ext.create('Ext.grid.RowNumberer'),

                { header: "图片ID", dataIndex: "Id", width: 80, sortable: true },

                { header: "频道ID", dataIndex: "ChannelId", width: 80, sortable: true },

                { header: "栏目ID", dataIndex: "ClassId", width: 80, sortable: true },

                { header: "标题", dataIndex: "Title", width: 80, sortable: true },

                { header: "标题颜色", dataIndex: "TColor", width: 80, sortable: true },

                { header: "添加时间", dataIndex: "AddDate", width: 80, sortable: true },

                { header: "简介", dataIndex: "Summary", width: 80, sortable: true },

                { header: "编辑人员", dataIndex: "Editor", width: 80, sortable: true },

                { header: "作者", dataIndex: "Author", width: 80, sortable: true },

                { header: "标签", dataIndex: "Tags", width: 80, sortable: true },

                { header: "查看数量", dataIndex: "ViewNum", width: 80, sortable: true },

                { header: "是否审核", dataIndex: "IsPass", width: 1, renderer: function(value) { if (value == "1") { return "是"; } else { return "否"; } }, sortable: true },

                { header: "是否图片", dataIndex: "IsImg", width: 1, renderer: function(value) { if (value == "1") { return "是"; } else { return "否"; } }, sortable: true },

                { header: "图片地址", dataIndex: "Img", width: 80, sortable: true },

                { header: "排序数", dataIndex: "OrderNum", width: 80, sortable: true },

                { header: "添加用户ID", dataIndex: "UserId", width: 80, sortable: true },

                { header: "阅读权限", dataIndex: "ReadGroup", width: 80, sortable: true },

                { header: "来源", dataIndex: "SourceFrom", width: 80, sortable: true },

                { header: "软件版本", dataIndex: "Version", width: 80, sortable: true },

                { header: "软件平台", dataIndex: "OperatingSystem", width: 80, sortable: true },

                { header: "解压密码", dataIndex: "UnZipPass", width: 80, sortable: true },

                { header: "演示地址", dataIndex: "DemoUrl", width: 80, sortable: true },

                { header: "官方/注册地址", dataIndex: "RegUrl", width: 80, sortable: true },

                { header: "大小", dataIndex: "SSize", width: 80, sortable: true },

                { header: "下载需点数", dataIndex: "Points", width: 80, sortable: true },

                { header: "下载地址", dataIndex: "DownUrl", width: 80, sortable: true },

                { header: "下载次数", dataIndex: "DownNum", width: 80, sortable: true },

                { header: "外部频道连接地址", dataIndex: "OutUrl", width: 80, sortable: true },

                { header: "阅读评论权限", dataIndex: "ReadComment", width: 80, sortable: true },

                { header: "评论权限", dataIndex: "WriteComment", width: 80, sortable: true },

                { header: "反对数量", dataIndex: "AgainstNum", width: 80, sortable: true },

                { header: "支持数", dataIndex: "SupportNum", width: 80, sortable: true },

                { header: "是否启用", dataIndex: "Enabled", width: 1, renderer: function(value) { if (value == "1") { return "是"; } else { return "否"; } }, sortable: true },
                { header: "删除", dataIndex: "Id", renderer: function(value) { return "<a href='javascript:void(0);' title='删除' onclick='DeleteModule_SoftFn()'class='deleteBtn' >&nbsp;&nbsp;&nbsp;</a>" }, width: 40 }    
            ]
        });
        Module_SoftStore.loadPage(1);
       
    }
    Module_SoftList();
